package leetcode.code0826;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {
		int n = difficulty.length, m = worker.length;
		int[][] jobs = new int[n][];
		for (int i = 0; i < n; i++) {
			jobs[i] = new int[] { difficulty[i], profit[i] };
		}
		Arrays.sort(jobs, (a, b) -> a[0] - b[0]);
		Arrays.sort(worker);
		int ans = 0, maxProfit = 0;
		for (int i = 0, j = 0; i < m; i++) {
			int ability = worker[i];
			while (j < n && jobs[j][0] <= ability) {
				maxProfit = Math.max(maxProfit, jobs[j][1]);
				j++;
			}
			ans += maxProfit;
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(100, this.maxProfitAssignment(H.str2array3("[2,4,6,8,10]"), H.str2array3("[10,20,30,40,50]"),
				H.str2array3("[4,5,6,7]")));
		H.compare(0, this.maxProfitAssignment(H.str2array3("[85,47,57]"), H.str2array3("[24,66,99]"),
				H.str2array3("[40,25,25]")));
		H.compare(190, this.maxProfitAssignment(H.str2array3("[13,37,58]"), H.str2array3("[4,90,96]"),
				H.str2array3("[34,73,45]")));
		
		
				
				

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
